package com.gold.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gold.entity.AdminUser;
import com.gold.mapper.AdminMapper;
import com.gold.myexception.Myexception;
import com.gold.service.AdminService;

@Service
public class AdminServiceImpl implements AdminService {

	@Autowired
	private AdminMapper am;

	public AdminUser selectAdminByAccount(String account) {
		AdminUser au = am.selectAdminByAccount(account);
		return au;
	}

	public List<AdminUser> selectAllAdmin() {
		return am.selectAllAdmin();
	}

	public AdminUser adminLogin(AdminUser au, AdminUser oldau) throws Myexception {
		if (oldau == null) {
			throw new Myexception("位置错误");
		}
		if (!oldau.getUserAccount().equals(au.getUserAccount())) {
			throw new Myexception("帐号不正确");
		}
		if (!oldau.getUserPwd().equals(au.getUserPwd())) {
			throw new Myexception("密码不正确");
		}
		return oldau;

	}

	public void checkCode(String adminCode, String checkCode) throws Myexception {
		if (!adminCode.equals(checkCode)) {
			throw new Myexception("验证码错误！");
		}
	}

}
